using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using Umdf.SideShow.Contents;
using Umdf.SideShow.Scf.ObjectModel;
using System.Xml.Serialization;

namespace Umdf.SideShow.Scf.Contents
{
    public class ScfContent : Content
    {
        private XmlDocument _rawXmlDoc;
        private ScfDocument _scfDocument;

        public ScfContent()
        {
        }

        public ScfContent(BinaryReader reader)
        {
            DeserializeObject(reader);
        }

        public ScfContent(uint id, XmlDocument scfDoc) : base(id)
        {
            _rawXmlDoc = scfDoc;
            _scfDocument = ScfDocument.Load(_rawXmlDoc);
        }

        
        public ScfDocument ScfDocument
        {
            get
            {
                if (_scfDocument == null)
                {
                    _scfDocument = ScfDocument.Load(_rawXmlDoc);
                }
                return _scfDocument;
            }
        }

        
        protected internal override void DeserializeObject(BinaryReader reader)
        {
            base.DeserializeObject(reader);
            _scfDocument = new ScfDocument();
            _scfDocument.DeserializeObject(reader);
        }

        protected internal override void SerializeObject(BinaryWriter writer)
        {
            base.SerializeObject(writer);
            ScfDocument.SerializeObject(writer);
        }
    }
}
